﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCRUM.Core.BusinessObjects;
using System.Data.Common;
using System.Collections;
using SCRUM.Core.DAO;
using System.Data;
using System.Web.UI.DataVisualization.Charting;

namespace SCRUM.Core.DataProviders
{
    /// <summary>
    /// Privider for comunication with the database for burndown chart
    /// </summary>
    public partial class DBDataProvider : DataProvider
    {
        /// <summary>
        /// Gets the progress for sprint.
        /// </summary>
        /// <param name="sprintID">The sprint ID.</param>
        /// <returns></returns>
        public override IList<DailyWorkProgress> GetProgressForSprint(int sprintID)
        {
            IList<DailyWorkProgress> output = new List<DailyWorkProgress>();
            try
            {
                connection.Open();

                DbParameter dbsprintID = CreateParameter("sprintID", sprintID);

                DbDataReader data = GetGrid("burndownchart/GetSource", dbsprintID);

                while (data.Read())
                {
                    DailyWorkProgress progress = new DailyWorkProgress(
                                                                       (DateTime)data[0],
                                                                       (double)data[1],
                                                                       (int)data[2]
                                                                      );
                    output.Add(progress);
                }
            }
            finally
            {
                connection.Close();
            }
            return output;
        }
    }
}